﻿using System;
using System.Collections.Generic;
using System.Data;

namespace MSSQL.Interface
{
	/// <summary>
	/// 实现了数据更新操作的接口（增删改）
	/// </summary>
	public interface IDataExcute
	{
		/// <summary>
		/// 设置该查询用例使用的库
		/// </summary>
		string DataBaseName { set; }

		/// <summary>
		/// 插入单条数据
		/// </summary>
		/// <typeparam name="T">对象类型</typeparam>
		/// <param name="t">数据对象</param>
		/// <returns>插入结果</returns>
		int InsertSingle<T>(T t);

		/// <summary>
		/// 插入多条数据
		/// </summary>
		/// <typeparam name="T">对象类型</typeparam>
		/// <param name="t">数据对象</param>
		/// <returns>插入结果</returns>
		int InsertMultiple<T>(IList<T> t);


		/// <summary>
		/// 执行事务
		/// </summary>
		/// <param name="sql">事务语句集</param>
		/// <param name="param">参数，可选，匿名类型</param>
		/// <param name="commandTimeOut">执行超时时间，可选，默认10秒</param>
		/// <param name="commandType">命令类型，可选，默认是CommandType.Text</param>
		/// <returns>执行结果</returns>
		int ExcuteTransaction(string sql, object param = null, int? commandTimeOut = 10, CommandType commandType = CommandType.Text);


		/// <summary>
		/// 更新单条数据
		/// </summary>
		/// <typeparam name="T">对象类型</typeparam>
		/// <param name="t">对象</param>
		/// <param name="where">where条件 如："where id = ...."</param>
		/// <returns>执行结果</returns>
		int UpdateSingle<T>(T t, string where);

		/// <summary>
		/// 更新单条数据
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="t"></param>
		/// <returns></returns>
		int UpdateSingle<T>(T t);

		/// <summary>
		/// 更新数据（sql）
		/// </summary>
		/// <param name="sql">sql</param>
		/// <param name="param">sql中需要的参数</param>
		/// <returns>更新结果</returns>
		int UpdateBySQL(String sql, object param);
	}
}
